package com.example.enjoyarkuix.fragment;

import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.enjoyarkuix.R;
import com.example.enjoyarkuix.DynamizationJumpActivity;
import com.example.enjoyarkuix.adapter.MyItemRecyclerViewAdapter;
import com.example.enjoyarkuix.bean.ItemDataBean;
import com.example.enjoyarkuix.common.Constant;
import com.example.enjoyarkuix.interfaces.OnItemClickListener;

import java.util.ArrayList;

/**
 * A simple {@link Fragment} subclass.
 * Use the {@link DemoFragment#newInstance} factory method to
 * create an instance of this fragment.
 */
public class DemoFragment extends BasesFragment {
    public static DemoFragment newInstance() {
        DemoFragment fragment = new DemoFragment();
        return fragment;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_demo, container, false);
        ArrayList<ItemDataBean> arrayList = new ArrayList();
        ItemDataBean itemDataBean0 = new ItemDataBean("一多", Constant.JUDPT_SHOW_ACTIVITY, Constant.PAGE_MULTI_DEVICE);
        ItemDataBean itemDataBean1 = new ItemDataBean("动态化", Constant.JUDPT_ANDROID_ACTIVITY, DynamizationJumpActivity.class);
        ItemDataBean itemDataBean2 = new ItemDataBean("C跨平台", Constant.JUDPT_SHOW_ACTIVITY, Constant.PAGE_C_CROSSPLATFORM);
        arrayList.add(itemDataBean0);
        arrayList.add(itemDataBean1);
        arrayList.add(itemDataBean2);

        // Set the adapter
        Context context = view.getContext();
        RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.list);
        recyclerView.setLayoutManager(new LinearLayoutManager(context));
        MyItemRecyclerViewAdapter myItemRecyclerViewAdapter = new MyItemRecyclerViewAdapter(arrayList);
        recyclerView.setAdapter(myItemRecyclerViewAdapter);

        myItemRecyclerViewAdapter.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(View view, int position) {
                judgePage(position, arrayList);
            }
        });
        return view;
    }
}